﻿@{
    Layout = "~/Views/Samples/Generic/_Index.cshtml";
}

@if (ViewBag.Project.ViewEngine == ViewEngine.WebForms)
{
    <asp:Panel ID="existingFilesPanel" runat="server" Visible="false">
        <h2>Existing Files</h2>
        <table class="results" width="99%" cellpadding="4" cellspacing="0">
            <thead>
                <th align="left">Name</th>
                <th align="left">Length (bytes)</th>
            </thead>
            <tbody>
            <asp:Repeater ID="filesRepeater" runat="server">
                <ItemTemplate>
                    <tr>
                        <td>
                            <a href="DownloadFile.ashx?id=<%#@SampleHelper.VaryByLanguage("((" + ViewBag.Project.Name + ".Storage.SqlFile)Container.DataItem).Id", "DirectCast(Container.DataItem, " + ViewBag.Project.Name + ".Storage.SqlFile).Id") %>" target="_blank"><%#@SampleHelper.VaryByLanguage("((" + ViewBag.Project.Name + ".Storage.SqlFile)Container.DataItem).Name", "DirectCast(Container.DataItem, " + ViewBag.Project.Name + ".Storage.SqlFile).Name") %></a>
                        </td>
                        <td>
                            <%#@SampleHelper.VaryByLanguage("((" + ViewBag.Project.Name + ".Storage.SqlFile)Container.DataItem).Length", "DirectCast(Container.DataItem, " + ViewBag.Project.Name + ".Storage.SqlFile).Length") %>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
            </tbody>
        </table>
        <br />
    </asp:Panel>
    <div id="errorMessage" runat="server" visible="false" enableviewstate="false" style="border:1px solid #c00;padding:.5em;margin-bottom:1em;">
        <b style="color:#f00">ERROR:</b> Could not connect to database. Please ensure the connection string and table information in the web.config are correct and that the file table has been properly created. Exception:<br /> <br />        
    </div>
}
else
{
    @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("if (Model.Exception == null) {", "If Model.Exception Is Nothing Then"))
        @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("if (Model.ExistingFiles.Count > 0) {", "If Model.ExistingFiles.Count > 0 Then"), true)
        <h2>Existing Files</h2>
        <table class="results" width="99%" cellpadding="4" cellspacing="0">
            <thead>
                <th align="left">Name</th>
                <th align="left">Length (bytes)</th>
            </thead>
            <tbody>
            @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("foreach (" + ViewBag.Project.Name + ".Storage.SqlFile file in Model.ExistingFiles) {", "For Each file As " + ViewBag.Project.Name + ".Storage.SqlFile In Model.ExistingFiles"))
                <tr>
                    <td>                        
                        @SampleHelper.RenderStatement(SampleHelper.VaryByLanguage("Html.ActionLink(file.Name, \"Download\", new { id = file.Id }, new { target=\"_blank\" })", "Html.ActionLink(file.Name, \"Download\", New With { .id = file.Id }, New With { .target = \"_blank\" })").ToString())
                    </td>
                    <td>
                        @SampleHelper.RenderStatement("file.Length")
                    </td>
                </tr>
            @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("}", "Next file"), true)
            </tbody>
        </table>
        <br />
        
        @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("}", "End If"), true)
    @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("} else {", "Else"), true)
    <div style="border:1px solid #c00;padding:.5em;margin-bottom:1em;">
        <b style="color:#f00">ERROR:</b> Could not connect to database. Please ensure the connection string and table information in the web.config are correct and that the file table has been properly created. Exception:<br /> <br />@SampleHelper.RenderStatement("Model.Exception.GetType().FullName"): @SampleHelper.RenderStatement("Model.Exception.Message")
    </div>
    @SampleHelper.RenderCode(SampleHelper.VaryByLanguage("}", "End If"), true)
}